package demoMod.invincibleOne.cards.invincible;

import basemod.helpers.CardModifierManager;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.rooms.MonsterRoom;
import com.megacrit.cardcrawl.rooms.MonsterRoomElite;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.enums.CardTagsEnum;
import demoMod.invincibleOne.interfaces.SpawnMonsterHook;
import demoMod.invincibleOne.modifiers.ExhaustAtStartOfCombatMod;
import demoMod.invincibleOne.powers.NeverGiveUpPower;
import demoMod.invincibleOne.relics.TaskGoal;

public class NeverGiveUp extends AbstractInvincibleCard implements SpawnMonsterHook {
    public static final String ID = InvincibleOneMod.makeID("NeverGiveUp");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/NeverGiveUp.png";

    private static final CardType TYPE = CardType.SKILL;
    private static final CardRarity RARITY = CardRarity.RARE;
    private static final CardTarget TARGET = CardTarget.NONE;

    private static final int COST = -2;

    public NeverGiveUp() {
        super(ID, NAME, InvincibleOneMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.modifier = new ExhaustAtStartOfCombatMod();
        CardModifierManager.addModifier(this, modifier);
        this.tags.add(CardTagsEnum.ALERT);
    }

    @Override
    public boolean onBattleStart() {
        if (AbstractDungeon.getCurrRoom().getClass().equals(MonsterRoom.class) || upgraded && AbstractDungeon.getCurrRoom().getClass().equals(MonsterRoomElite.class)) {
            TaskGoal.AddToAlertQueue(2, new TaskGoal.AlertLambda() {
                @Override
                public void run() {
                    for (AbstractMonster m : AbstractDungeon.getMonsters().monsters) {
                        addToBot(new ApplyPowerAction(m, m, new NeverGiveUpPower(m, 1)));
                    }
                }
            });
        }
        return true;
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> {
            this.rawDescription = cardStrings.UPGRADE_DESCRIPTION;
            this.initializeDescription();
        };
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {

    }

    @Override
    public void onSpawnMonster(AbstractMonster m) {
        if (AbstractDungeon.getCurrRoom().getClass().equals(MonsterRoom.class) || upgraded && AbstractDungeon.getCurrRoom().getClass().equals(MonsterRoomElite.class)) {
            TaskGoal.AddToAlertQueue(2, new TaskGoal.AlertLambda() {
                @Override
                public void run() {
                    addToBot(new ApplyPowerAction(m, m, new NeverGiveUpPower(m, 1)));
                }
            });
        }
    }
}
